package com.car.mgr.web.qdsl.utils;

import java.io.Serializable;
import java.lang.String;
import java.lang.SuppressWarnings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RestResult implements Serializable {
  private static final long serialVersionUID = 1L;

  private int code;

  private String msg;

  private Object data;

  public static RestResult ok(Object data) {
    return RestResult.result(HttpStatus.OK, data);
  }

  public static RestResult result(ErrorCode errorCode, Object data) {
    return RestResult.builder().code(errorCode.getCode()).msg(errorCode.getMsg()).data(data).build();
  }

  public static RestResult result(HttpStatus httpStatus, Object data) {
    return RestResult.builder().code(httpStatus.value()).msg(httpStatus.name()).data(data).build();
  }
}
